package com.appbee.core.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class NamedPlace extends Place implements INamePlace
{
	private String name;
	
	public NamedPlace(){}
	
	public NamedPlace(String name)
	{
		this.name = name;
	}

	@Override
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}
	
	public String[] getPathElements()
	{
		return name.split("_");
	}

	public String getRootElement()
	{
		return getPathElements()[0];
	}

	@Prefix("n")
	public static class Tokenizer implements PlaceTokenizer<NamedPlace>
	{

		@Override
		public NamedPlace getPlace(String token)
		{
			NamedPlace p = new NamedPlace(token);
			return p;
		}

		@Override
		public String getToken(NamedPlace place)
		{
			return place==null?"":place.getName();
		}
		
	}
}
